﻿package com.zit.service;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.zit.dao.CourseDAO;
import com.zit.dao.ProfessionDAO;
import com.zit.dao.TermDAO;
import com.zit.entity.Course;
import com.zit.entity.Profession;
import com.zit.entity.Term;

/**
 * 功能：关于课程管理的服务层
 * @author 唐美兰
 *
 * date2013-12-3 time下午04:24:22
 */
public class CourseService extends BaseService {
	CourseDAO courses=new CourseDAO();
	ProfessionDAO professions=new ProfessionDAO();
	TermDAO terms=new TermDAO();
	/**
	 * 功能：添加课程
	 * @param c
	 */
	public void save(Course c) {
		Session s = null;
		Transaction tx = null ;
		try {
			s = getSession();
			tx = s.beginTransaction();
			courses.save(c, s);
			tx.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			s.close();
		}
	}

	
	/**
	 * 功能：查询学期
	 * @return
	 */
	public List<Term> showTerm() {
		Session s = null;
		Transaction tx = null ;
		List<Term> list = null ;
		try {
			s = getSession();
			tx = s.beginTransaction();
			list =terms.showTerm(s);
			tx.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			s.close();
		}
		return list ;
	}
	
	
	/**
	 * 功能：查询专业
	 * @return
	 */
	public List<Profession> showProfession() {
		Session s = null;
		Transaction tx = null ;
		List<Profession> list = null ;
		try {
			s = getSession();
			tx = s.beginTransaction();
			list =professions.showprofession(s);
			tx.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			s.close();
		}
		return list ;
	}
	/**
	 * 功能：查询专业
	 * @return
	 */
	public List<Course> showcourse(int termid) {
		Session s = null;
		Transaction tx = null ;
		List<Course> list = null ;
		try {
			s = getSession();
			tx = s.beginTransaction();
			list =courses.showcourse(termid, s);
			tx.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			s.close();
		}
		return list ;
	}
}
